import { DataBase, DataStructure } from "./database";


enum LOG_TYPE {
    LED_TEXT,
}

/** LED日志 */
export class LedLogs extends DataBase {
    public static collectionName: string = "LedLogs";

    public deviceId: string;
    public logType: LOG_TYPE;
    public ledText: string;

    constructor(data: DataStructure = {}) {
        super(data);
        this.deviceId = data['deviceId'] || ''
        this.logType = data['logType']
        this.ledText = data['ledText'] || ''
    }

    /** LED轮播文本的日志 */
    public static async GetLedTextLogs(deviceId: string, offset: number = 0) {
        const orderBy: OrderByArray = {
            fieldPath: 'otherInformation.createDate',
            string: 'desc',
        }
        const a = await LedLogs.GetData({
            deviceId: deviceId,
            logType: LOG_TYPE.LED_TEXT,
        }, offset, undefined, [orderBy]);
        return a.map(x => new LedLogs(x));
    }

    /** 保存LED文本日志 */
    public static async SaveLedText(deviceId: string, ledText: string) {
        return await this.AddData(new LedLogs({
            logType: LOG_TYPE.LED_TEXT,
            deviceId,
            ledText,
        }))
    }

}